package org.bingo.web.config;

import io.swagger.annotations.ApiOperation;
import org.bingo.config.BingoConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author mj
 * @version 1.0
 * @date 2022/2/23 0023 下午 20:49
 **/
@Configuration
public class SwaggerConfig {
    @Autowired
    BingoConfig bingoConfig;
    /**
     * 创建API
     * swagger文档访问路径：http://localhost:8080/bingo/swagger-ui/index.html
     */
    @Bean
    public Docket createRestApi()
    {
        return new Docket(DocumentationType.OAS_30)
                // 用来创建该API的基本信息，展示在文档的页面中（自定义展示的信息）
                .apiInfo(apiInfo())
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 扫描所有标有@ApiOperation注解的api,标有该注解的api会被写在文档里
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();

    }
    /**
     * 添加摘要信息
     */
    private ApiInfo apiInfo()
    {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                // 设置标题
                .title("标题：Bingo系统_接口文档")
                // 描述
                .description("描述：这是一个集成视频与贴文的社交系统"+"，该系统创建于"+bingoConfig.getBuildTime())
                // 版本
                .version(bingoConfig.getBingoVersion())
                .build();
    }
}
